#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N = 2e5;
const int maxn = 1e6;
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

pair<int, pair<int, int>> node[N + 10];
pair<int,int> pos_node[N + 10];
int pos;
int val;

void solve()
{
	int n, m;
	sd(n); sd(m);
	for (int i = 0; i <m; i++)
	{
		sd(pos); sd(val);
		node[i].fi = val;
		node[i].se.fi = pos;
		node[i].se.se = i + 1;
	}
	sort(node, node + m);
	ll sum = 0;
	for (int i = 0; i < n * 2; i++)
	{
		sum += node[i].fi;
		pos_node[i].se = node[i].se.se;
		pos_node[i].fi=node[i].se.fi;
	}
	sort(pos_node, pos_node + 2 * n);

	cout << sum << '\n';
	for (int i = 0, j = n * 2 - 1; i < j; i++, j--)
	{
		cout << pos_node[i].se << " " << pos_node[j].se;
		puts("");
	}
	puts("");

}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}